
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_member_photos.
	''' </summary>
	Public Partial Class view_member_photos
		Inherits BaseWebPage
		Protected lblCommentsCount As System.Web.UI.WebControls.Label

		Protected id As Integer = -1

		Public Function CreateDataSource() As ICollection
			Dim usr As BO.User = Users.GetUserByID(id)

			If usr <> Nothing Then
				Dim pics As ArrayList = usr.GetPictures()
				Dim picsCount As Integer = pics.Count
				If picsCount = 0 Then
					lblNoImage.Visible = True
				Else
					lblNoImage.Visible = False
				End If

				Dim dt As New DataTable()
				Dim dr As DataRow

				dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
				dt.Columns.Add(New DataColumn("ImageID", GetType(String)))
				dt.Columns.Add(New DataColumn("Description", GetType(String)))
				dt.Columns.Add(New DataColumn("Comments", GetType(String)))
				dt.Columns.Add(New DataColumn("UserName", GetType(String)))

				Dim tmpCommentsCount As Integer = 0
				Dim i As Integer = 0
				While i < picsCount
					dr = dt.NewRow()

					Dim temp As UserPicture = DirectCast(pics(i), UserPicture)
					dr(0) = Pictures.GetPictureSrcFullURL(temp, True, "../")
					dr(1) = temp.ID.ToString()
					If temp.Desc = "" Then
						dr(2) = "&nbsp;"
					Else
						dr(2) = temp.Desc
					End If

					tmpCommentsCount = temp.Comments.Count
					If temp.User.ApproveComments Then
						tmpCommentsCount += temp.NewComments.Count
					End If

					dr(3) = tmpCommentsCount + " Comment"

					If tmpCommentsCount <> 1 Then
						dr(3) = dr(3) + "s"
					End If
					dr(4) = usr.Name
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While

				Dim dv As New DataView(dt)
				Return dv
			End If
			Return Nothing

		End Function
		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			Dim usr As User = LoggedUser

			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			Me.initPageTitles(Constants.VIEW_MEMBER_PHOTOS_PAGE, "", uploadImageForm, Nothing, Nothing)
			Me.initAdvertisements(uploadImageForm, Nothing)
			' this.pageTemplate.PageTitle = PageTitles.MEMBERS_PAGE;
			id = Convert.ToInt32(Request.Params("id"))

			Dim member As BO.User = Users.GetUserByID(id)

			If member <> Nothing AndAlso member.ID <> usr.ID Then
				ucMemberShortcut.UserID = id
			Else
				trUserShortCut.Visible = False
			End If

			If Not IsPostBack Then
				BindList()
			End If
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dlPictures.ItemCommand, AddressOf Me.dlPictures_ItemCommand

		End Sub
#End Region

		Public Sub BindList()
			dlPictures.DataSource = CreateDataSource()
			dlPictures.DataBind()
		End Sub

		Public Sub dlPictures_ItemCommand(ByVal Sender As Object, ByVal e As DataListCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim cmd As String = ""
			Dim usr As BO.User = Users.GetUserByID(id)
			Dim type As String = src.[GetType]().ToString()
			Select Case type
				Case "System.Web.UI.WebControls.ImageButton"
					cmd = (DirectCast(src, ImageButton)).CommandName
					Exit Select
				Case "System.Web.UI.WebControls.LinkButton"
					cmd = (DirectCast(src, LinkButton)).CommandName
					Exit Select
				Case "System.Web.UI.WebControls.Button"
					cmd = (DirectCast(src, Button)).CommandName
					Exit Select
			End Select
			Select Case cmd
				Case "ViewLargerPhotoLink"
					Response.Redirect(Constants.VIEW_PHOTO_ALBUM_COMMENTS_PAGE + "?img=" + e.CommandArgument.ToString() + "&usr=" + usr.ID)
					Exit Select
				Case "PostComment"
					Response.Redirect(Constants.ADD_PHOTO_ALBUM_COMMENTS + "?img=" + e.CommandArgument.ToString() + "&usr=" + usr.ID)
					Exit Select
			End Select
			BindList()
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable uploadImageForm.
		====================
		Public ReadOnly Property uploadImageForm() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_uploadImageForm
			End Get
		End Property
		'set { Migrated_uploadImageForm = value; }
	End Class
End Namespace






